package cn.exrick.manager.service.hotclassload;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

import java.util.Collections;
import java.util.List;

public class Test {

    public static void main(String[] args) throws Exception{
        Multimap<String,String> multimap =  ArrayListMultimap.create();
        multimap.put("aa","a1");
        multimap.put("aa","a2");
        multimap.put("bb","b2");
        System.out.println(multimap.get("aa"));

        Joiner joiner = Joiner.on("|").useForNull("@");
        System.out.println(joiner.join("a","b",null,"c"));
        StringBuilder builder= new StringBuilder();
        System.out.println(joiner.appendTo(builder, Lists.newArrayList("a",null," b b ","c")).toString());

        Splitter splitter = Splitter.on("|").trimResults();
        List<String> ss = splitter.splitToList(builder.toString());
        System.out.println(ss.toString());

        List<Integer> list = Lists.newArrayList();
        list.add(1);
        list.add(2);
        List<Integer> result = Collections.unmodifiableList(list);
        list.add(3);
        System.out.println(list.size());
        System.out.println(result.size());


       /* CacheLoader<String, DecorationLoanOutputDTO> cacheLoader = new CacheLoader<String, DecorationLoanOutputDTO>() {
            @Override
            public DecorationLoanOutputDTO load(String key) throws Exception {
                DecorationLoanOutputDTO decorationLoanOutputDTO = new DecorationLoanOutputDTO();
                decorationLoanOutputDTO.setLoanId(key);
                return decorationLoanOutputDTO;
            }
        };*/
       /* DecorationLoanOutputDTO decorationLoanOutputDTO = new DecorationLoanOutputDTO();
        decorationLoanOutputDTO.setLoanId("aa");
        decorationLoanOutputDTO.setName("test");
       CacheLoader<String,DecorationLoanOutputDTO> cacheLoader = new MyCacheLoader<>(decorationLoanOutputDTO);

        LoadingCache<String,DecorationLoanOutputDTO> cache = CacheBuilder.newBuilder().expireAfterAccess(24L, TimeUnit.HOURS).expireAfterWrite(24L,TimeUnit.HOURS).maximumSize(2000L).build(cacheLoader);
        //cacheLoader.load("aa");
        System.out.println(cache.get(""));*/


    }

    static class MyCacheLoader<R,T> extends CacheLoader<R,T>{

        private T t;

        MyCacheLoader(T t){
            this.t = t;
        }
        @Override
        public T load(R key) throws Exception {
            return t;
        }
    }
}
